package com.yy.util;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2015/6/15.
 */
public abstract class BaseFragment extends Fragment implements View.OnClickListener {

    protected AppBaseActivity mActivity;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if(activity instanceof AppBaseActivity) {
            mActivity = (AppBaseActivity) activity;
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        int layoutId = getLayoutId();
        if(layoutId != 0) {
            View view = inflater.inflate(layoutId, container, false);
            initView(view);
            return view;
        }
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(isVisibleToUser) {
            userVisible();
        } else {
            userInvisible();
        }
    }

    protected void initView(View view) {

    }

    protected abstract int getLayoutId();

    public void userVisible() {

    }

    public void userInvisible() {

    }

    @Override
    public void onClick(View v) {

    }
}
